﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DataAccess;
using DataAccess.Object;
namespace Business
{
    public class SanPhamBUS
    {
        SanPhamDAO spDAO = new SanPhamDAO();
        public DataTable DS_SP_byname(string tensp)
        {
            return spDAO.DS_SP_byname(tensp);
        }

        public DataTable DanhSachSP(string id)
        {
            return spDAO.DS_SP(id);
        }
        public DataTable TenSP()
        {
            return spDAO.TenSP();
        }
        public DataTable MaSP(string tensp)
        {
            return spDAO.MaSP(tensp);
        }
        public DataTable idNhanVien(string ten)
        {

            return spDAO.idNhanvien(ten);
        }
        public void xoaSP_DH(string id)
        {
            spDAO.xoaSP_DH(id);
        }
        public void themSP(SanPhamOB sp)
        {
            spDAO.themSP(sp);
        }
       

        public void suaSP(SanPhamOB sp)
        {
            spDAO.suaSanPham(sp);
        }
        public DataTable DanhSachSP()
        {
            return spDAO.DanhSachSP();
        }
        
        public DataTable sanphambyid(string ma_sp) 
        {
            return spDAO.SanPham_By_Id(ma_sp);
        }

        public void xoaSP(string idSelect)
        {
            spDAO.xoaSanPham(idSelect);
        }

        public DataTable DanhSachSPbyid(string ma_sp)
        {
            return spDAO.danhsachspbyid(ma_sp);
        }


        public DataTable TimKiemSP(string ma_sp, string ten_sp)
        {
            string where = "";
            string conditon = "";
            string str = "";
            if (ma_sp != "")
            {
                str += conditon + " ma_sp like '%" + ma_sp + "%' ";
                conditon = " and ";
            }
            if (ten_sp != "")
            {
                str += conditon + " ten_sp like '%" + ten_sp + "%' ";
                conditon = " and ";
            }
            if (str.Length > 0)
            {
                where = " where " + str;
            }
            return spDAO.TimKiemsp(where);
        }

        public bool kiemtrama(string id)
        {
            DataTable dt = spDAO.danhsachspbyid(id);
            if (dt != null && dt.Rows.Count > 0)
            {
                return false;
            }
            return true;
        }
    }
}
